@extends('backstage.layout.master')
@section('title', '推送消息')

@section('script')
	<script type="text/javascript">
			function pushmessage(){
				swal({
					title:"确认推送吗？",
					text:"",
					type:"warning",
					showCancelButton: true,
					confirmButtonColor: "#DD6B55",
					confirmButtonText: "确定",
					cancelButtonText:"取消",
					closeOnConfirm: false,
					closeOnCancel: true
				},function(){
					var body	= $("#body").val().trim();
					if(body==null||body==""){
						swal('请输入要推送的内容','','warning');
						return;
					}
					var arrobj	= new Array();
					$("#plat input[name=check-box]:checked").each(function(){
						arrobj.push($(this).val());
					});
					if(arrobj==null||arrobj==""){
						arrobj	= 0;
					}

					var cla	  = $("#class").val();
					var title = $("#title").val();
					var reg_id= $("#reg_id").val();

					$.ajax({
						url:"/backstage/jpush/pushmessage",
						type:"post",
						data:{"body":body,"plat":arrobj,'title':title,"class":cla,"reg_id":reg_id},
						datetype:"json",
						success:function(re){
							if(re.state=="M00000"){
								swal(re.message,'','success');
								return;
							}
							swal(re.message,'','warning');
						},
						error:function(){
							swal('','系统繁忙，请稍后重试','warning');
						}
					});
				});
			}
    </script>
@stop

@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/jpush/showpushmessage">推送消息</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
						推送
                        <small>
                            <i class="icon-double-angle-right"></i>
                            推送消息
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="page-content">
                            <div class="page-header preview-header">
                                <h1>
									推送页面内容:
                                </h1>
                            </div><!-- /.page-header -->

                            <div class="form-horizontal">
								<div class="form-group {{$errors->first('title')!=''?'has-error':''}}">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 推送平台 </label>
									<div id="plat" class="col-sm-4">
										<a>
											<input type="checkbox" name="check-box" value="ios" style="margin-top:9px;"/> 
											<span style="margin-right: 5px;">IOS</span>
											<input type="checkbox" name="check-box" value="android" style="margin-top:9px;"/>
											<span>Android</span>
										</a>
									</div>
									<div class="col-sm-4">
										<div class="help-block col-xs-12 col-sm-reset inline"> 若不选默认为所有平台</div>
									</div>
								</div>
								<div class="form-group {{$errors->first('title')!=''?'has-error':''}}">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 消息类别 </label>
									<div class="col-sm-4">
										<select id="class">
											@if(isset($class))
											@foreach($class as $cla)
											<option value="{{isset($cla->class)?$cla->class:''}}">{{isset($cla->class_name)?$cla->class_name:''}}</option>
											@endforeach
											@endif
										</select>
									</div>
									<div class="col-sm-4">
										<div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('title')}}</div>
									</div>
								</div>
								<div class="form-group {{$errors->first('reg_id')!=''?'has-error':''}}">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 资源编号 </label>
									<div class="col-sm-4">
										<input type="text" class="width-80" id="reg_id" placeholder="系统消息可不填写"/>
									</div>
									<div class="col-sm-4">
										<div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('reg_id')}}</div>
									</div>
								</div>
								<div class="form-group {{$errors->first('title')!=''?'has-error':''}}">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 标题 </label>
									<div class="col-sm-4">
										<textarea class="form-control" name="title" id="title"></textarea>
										<span>推送消息只显示前58个汉字</span>
									</div>
									<div class="col-sm-4">
										<div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('title')}}</div>
									</div>
								</div>
								<div class="form-group {{$errors->first('body')!=''?'has-error':''}}">
									<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> 内容 </label>
									<div class="col-sm-4">
										<textarea class="form-control" name="body" id="body"></textarea>
									</div>
									<div class="col-sm-4">
										<div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('body')}}</div>
									</div>
								</div>
							</div>
							<div class="clearfix form-actions"	>
                                <div class="col-md-offset-5 col-md-9">
                                    <button class="btn btn-info" onclick="pushmessage();">
                                        <i class="icon-ok bigger-110"></i>
                                        推送
                                    </button>
								</div>
							</div>


						</div><!-- /page-content -->
					</div><!-- col -->
				</div><!-- row -->
			</div><!-- col -->
		</div><!-- row -->
    </div><!-- /.page-content -->
                        
@stop
@section('script')
    <script src="backstage/assets/js/jquery.colorbox-min.js"></script>
	
    
@stop